<?php /* Smarty version 2.6.20, created on 2011-11-18 16:52:55
         compiled from _core/pagecommon/_mvc/_control/handlepageb1orderdiscount.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/pagecommon/_mvc/_control/handlepageb1orderdiscount.tpl', 9, false),)), $this); ?>
function HandlePageB1OrderDiscount(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  if (this._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
    this._cond = 'WHERE o.isOrderDiscountSolved != 2';
    this._type = '<?php echo ((is_array($_tmp=@APPROVE_TYPE_NOTAPPROVED)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
';
    this._button = DOMUtils.createInput('', '', 'button', 'Approve', null);
    this._gui.save.appendChild(this._button);
  } else {
    this._cond = 'WHERE o.isOrderDiscountSolved = 0';
    this._type = '<?php echo ((is_array($_tmp=@SOLVE_TYPE_NOTSOLVED)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
';
    this._button = DOMUtils.createInput('', '', 'button', 'Solve', null);
    this._gui.save.appendChild(this._button);
  }
  
  this._createElements();
};

HandlePageB1OrderDiscount.prototype._createElements = function() {
  var tr, td, _self = this;
  
  tr = this._gui.main.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 4;
  td.appendChild(DOMUtils.getLoadingImage());
  
  if (this._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
    for (var i = 0, il = ApproveType.array().length; i < il; i++) {
      var type = ApproveType.array()[i];
      option = new Option(type);
      this._gui.select.options[this._gui.select.options.length] = option;
      if (option.text == this._type) {
        this._gui.select.selectedIndex = this._gui.select.options.length - 1;
      }
    }
    
    this._gui.select.onchange = function() { _self._type = this.options[this.selectedIndex].text;
                                             if (_self._type == '<?php echo ((is_array($_tmp=@APPROVE_TYPE_NOTAPPROVED)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                               _self._cond = 'WHERE o.isOrderDiscountSolved != 2';
                                             } else {
                                               _self._cond = null;
                                             }
                                             _self._retrieveCustomers(1);
                                           };
  } else {
    for (var i = 0, il = SolveType.array().length; i < il; i++) {
      var type = SolveType.array()[i];
      option = new Option(type);
      this._gui.select.options[this._gui.select.options.length] = option;
      if (option.text == this._type) {
        this._gui.select.selectedIndex = this._gui.select.options.length - 1;
      }
    }
    
    this._gui.select.onchange = function() { _self._type = this.options[this.selectedIndex].text;
                                             if (_self._type == '<?php echo ((is_array($_tmp=@SOLVE_TYPE_NOTSOLVED)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                               _self._cond = 'WHERE o.isOrderDiscountSolved = 0';
                                             } else {
                                               _self._cond = 'WHERE o.isOrderDiscountSolved != 2';
                                             }
                                             _self._retrieveCustomers(1);
                                           };
  }

  this._loadData();
};

HandlePageB1OrderDiscount.prototype._loadData = function() {
  this._orders = null;
  this._parameters = null;
  this._retrieveCustomers(1);
};

HandlePageB1OrderDiscount.prototype._verifyData = function() {
  if (this._orders) {
    this._updateElements();
  }
};

HandlePageB1OrderDiscount.prototype._retrieveCustomers = function(page) {
  var _self = this;
  var args = ((this._cond) ? '&c=' + this._cond : '') + '&s=20' + '&p=' + page;
  new RequestUtils()._mysql('orderdiscount', args, function(result, params) { _self._orders = result.data;
                                                                              _self._parameters = result;
                                                                              _self._verifyData.call(_self);
                                                                            }, null);
};

HandlePageB1OrderDiscount.prototype._updateElements = function() {
  var tr, td, _self = this;
  DOMUtils.removeTableRows(this._gui.main, 1);
  DOMUtils.removeChildElements(this._gui.page);
  var unique = MiscUtils.unique();
  DOMUtils.removeChildElements(this._gui.checkAll);
  this._selects = [];
  
  if (this._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
    this._button.onclick = function() { if (_self._selects.length == 0) {
                                          window.alert('No Items Selected');
                                          return;
                                        }
                                        var objects = [];
                                        for(var i = 0, il = _self._selects.length; i < il; i++) {
                                          var object = _self._selects[i];
                                          objects[objects.length] = object.id;
                                        }
                                        new RequestUtils()._mysql('discount', '&o=' + JSON.stringify(objects), function(result, params) { _self._retrieveCustomers(_self._parameters.page); }, { pos: DOMUtils.findPos(this) });
                                      };

    if (this._orders.length == 0) {
      tr = this._gui.main.insertRow(-1);
      td = tr.insertCell(-1);
      td.style.height = '24px';
      td.style.textAlign = 'center';
      td.colSpan = 4;
      td.style.backgroundColor = '#fff';
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.borderLeft = 'solid 1px #694247';
      td.appendChild(document.createTextNode('N/A'));
    }
  
    for(var i = 0, il = this._orders.length; i < il; i++) {
      var o = this._orders[i];
      tr = this._gui.main.insertRow(-1);
      tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#faf9f4' : '#ffffff';
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.borderLeft = 'solid 1px #694247';
      var check = DOMUtils.createInput(null, unique + '_' + i, 'checkbox', '', null);
      check._order = o;
      check.onclick = function() { if (this.checked == true) {
                                     _self._selects[_self._selects.length] = this._order;
                                   } else {
                                     MiscUtils.remove(_self._selects, this._order, 'trackId');
                                   }
                                 };
      if (o.isOrderDiscountSolved != 2) {
        td.appendChild(check);
      }
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.textAlign = 'center';
      td.appendChild(document.createTextNode((o.isOrderDiscountSolved == 0) ? 'Not Solved' : (o.isOrderDiscountSolved == 1) ? 'Solved' : 'Approved'));
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.padding = '0 0 0 15px';
      td.style.height = '25px';
      var a = document.createElement('a');
      a.href = '#';
      a._c = o;
      a.appendChild(document.createTextNode(DlmanageUtils.customerId(o.customerId) + o.flag + ' ' + o.discount + '%'));
      a.onclick = function() {location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId, isAdmin: true }); return false;};
      td.appendChild(a);
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.textAlign = 'left';
      td.style.padding = '0 0 0 15px';
      var span1 = document.createElement('span');
      td.appendChild(span1);
      span1.style.lineHeight = '24px';
      span1.appendChild(document.createTextNode(((o.note) ? ((String(o.note).length > 60) ? o.note.substring(0, 60) + '...' : o.note) : '(None)' )));
      if (o.note && o.note.length > 60) {
        var a = document.createElement('a');
        a.href = '#';
        a._order = o;
        a.appendChild(document.createTextNode('All'))
        a.onclick = function() { var pos, func1, func2;
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 func1 = function() { _self._popupBox._close();
                                                    };
                                 div.appendChild(MiscUtils.span(this._order.note));
                                 MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                 return false;
                               };
        td.appendChild(a);
      }
    }
  } else {
    this._button.onclick = function() { if (_self._selects.length == 0) {
                                          window.alert('No Items Selected');
                                          return;
                                        }
                                        var objects = [];
                                        for(var i = 0, il = _self._selects.length; i < il; i++) {
                                          var object = _self._selects[i];
                                          objects[objects.length] = object.id;
                                        }
                                        new RequestUtils()._mysql('discount1', '&o=' + JSON.stringify(objects), function(result, params) { _self._retrieveCustomers(_self._parameters.page); }, { pos: DOMUtils.findPos(this) });
                                      };

    if (this._orders.length == 0) {
      tr = this._gui.main.insertRow(-1);
      td = tr.insertCell(-1);
      td.style.height = '24px';
      td.style.textAlign = 'center';
      td.colSpan = 4;
      td.style.backgroundColor = '#fff';
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.borderLeft = 'solid 1px #694247';
      td.appendChild(document.createTextNode('N/A'));
    }
  
    for(var i = 0, il = this._orders.length; i < il; i++) {
      var o = this._orders[i];
      tr = this._gui.main.insertRow(-1);
      tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#faf9f4' : '#ffffff';
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.borderLeft = 'solid 1px #694247';
      var check = DOMUtils.createInput(null, unique + '_' + i, 'checkbox', '', null);
      check._order = o;
      check.onclick = function() { if (this.checked == true) {
                                     _self._selects[_self._selects.length] = this._order;
                                    } else {
                                     MiscUtils.remove(_self._selects, this._order, 'trackId');
                                    }
                                  };
      if (o.isOrderDiscountSolved == 0) {
        td.appendChild(check);
      }
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.textAlign = 'center';
      td.appendChild(document.createTextNode((o.isOrderDiscountSolved == 0) ? 'Not Solved' : (o.isOrderDiscountSolved == 1) ? 'Solved' : 'Approved'));
      
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.padding = '0 0 0 25px';
      td.style.height = '25px';
      var a = document.createElement('a');
      a.href = '#';
      a._c = o;
      a.appendChild(document.createTextNode(DlmanageUtils.customerId(o.customerId) + o.flag + ' ' + o.discount + '%'));
      a.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                 location.href = '?p=pageasst&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId}); 
                                 return false;
                               } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                 location.href = '?p=pageserv&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId}); 
                                 return false;
                               } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                 location.href = '?p=pagemanager&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId}); 
                                 return false;
                               }else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ACCOUNTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                 location.href = '?p=pageacct&t=pagecustomerold&m=' + JSON.stringify({ a: 3, b: 3 ,e: 2}) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId}); 
                                 return false;
                               }
                             };
      td.appendChild(a);
      
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #694247';
      td.style.borderBottom = 'solid 1px #694247';
      td.style.textAlign = 'left';
      td.style.padding = '0 0 0 15px';
      var span1 = document.createElement('span');
      td.appendChild(span1);
      span1.style.lineHeight = '24px';
      span1.appendChild(document.createTextNode(((o.note) ? ((String(o.note).length > 40) ? o.note.substring(0, 40) + '...' : o.note) : '(None)' )));
      if (o.isOrderDiscountSolved == 0) {
        var img = document.createElement('img');
        img.src = 'images/common/edit.png';
        img.style.cursor = 'pointer';
        img._order = o;
        img.onclick = function() { var pos, func1, func2;
                                   var pos = DOMUtils.findPos(this);
                                   var div = document.createElement('div');
                                   var note = MyOrderNote.instance();
                                   var order = this._order;
                                   func1 = function() { note.orderDiscountNote = note._text;
                                                        note.orderId = order.id;
                                                        new RequestUtils()._mwrite('myordernote', [note], [], function() { _self._retrieveCustomers(1); }, { pos: pos });
                                                        _self._popupBox2._close();
                                                      };
                                   var func2 = function() { _self._popupBox2._close(); };
                                   MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Explanation Reason'});
                                   new DialogInput(div, note, { title: '', default: order.note });
                                   return false;
                                 };
        td.appendChild(img);
      } else if (o.note && o.note.length > 40) {
        var img = document.createElement('img');
        img.src = 'images/common/enlarge.png';
        img.style.cursor = 'pointer';
        img._order = o;
        img.onclick = function() { var pos, func1, func2;
                                   var pos = DOMUtils.findPos(this);
                                   var div = document.createElement('div');
                                   func1 = function() { _self._popupBox._close();
                                                      };
                                   div.appendChild(MiscUtils.span(this._order.note));
                                   MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                   return false;
                                 };
        td.appendChild(img);
      }
    }
  }
  
  this._gui.checkAll.checked = false;
  this._gui.checkAll._unique = unique;
  this._gui.checkAll.onclick = function() { if (this.checked == true) {
                                             for (var i = 0, il = _self._orders.length; i < il; i++) {
                                                var object = _self._orders[i];
                                                if (document.getElementById(this._unique + '_' + i) && !document.getElementById(this._unique + '_' + i).checked) {
                                                  _self._selects[_self._selects.length] = object;
                                                  document.getElementById(this._unique + '_' + i).checked = true;
                                                }
                                              }
                                            } else {
                                              for (var i = 0, il = _self._orders.length; i < il; i++) {
                                                var object = _self._orders[i];
                                                if (document.getElementById(this._unique + '_' + i)) {
                                                  MiscUtils.remove(_self._selects, object, 'trackId');
                                                  document.getElementById(this._unique + '_' + i).checked = false;
                                                }
                                              }
                                            }
                                          };
                                          
  /*--PAGINATION--*/
  Pagination.makePagedResults(this._gui.page, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveCustomers.call(_self, page, _self._parameters.condition); }, this, document);
};
